import { Component } from '@angular/core';
import { NavController, NavParams, ViewController } from 'ionic-angular';
import { ActiveDataProvider } from '../../providers/active-data/active-data';
import { Actives } from '../active/actives';

/**
 * Generated class for the InputActivesPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@Component({
  selector: 'page-input-actives',
  templateUrl: 'input-actives.html',
})
export class InputActivesPage {

  title: string;
  status: string = 'open';
  description: string;
  objectId: string;

  action:string ='发起';

  constructor(public navCtrl: NavController, 
    public navParams: NavParams,
    public viewCtrl:ViewController,
    public http:ActiveDataProvider) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad InputActivesPage');
  }

  close(){
    this.viewCtrl.dismiss();
  }

  saveActives(){
    let _actives : Actives ={
      title: this.title,
      status: this.status,
      description: this.description,
      objectId: this.objectId,
    };
    if (this.action === '发起') {
      this.http.addActives(_actives).subscribe(data => _actives.objectId = data.objectId);
    }else if (this.action === '编辑') {
      this.http.updateActives(_actives).subscribe();
    }
    this.viewCtrl.dismiss(_actives);
  }

}
